/*
 * @Description: Vuex
 * @Autor: 赖维健(lwj1994)
 * @Date: 2021-09-28 09:57:42
 * @LastEditors: 赖维健(lwj1994)
 * @LastEditTime: 2021-09-28 19:00:10
 */
import { createStore } from 'vuex'

const store = createStore({
  state: {
    defaultTheme: null,
    activeTheme: null,
  },

  getters: {
    defaultTheme: state => state.defaultTheme,
    activeTheme: state =>
      state.activeTheme ||
      (localStorage.getItem('activeTheme') &&
        JSON.parse(localStorage.getItem('activeTheme'))) ||
      state.defaultTheme,
  },

  mutations: {
    // 设置默认主题
    setDefaultTheme(state, data) {
      state.defaultTheme = data
    },

    // 设置当前主题
    setActiveTheme(state, data) {
      state.activeTheme = data
      localStorage.setItem('activeTheme', JSON.stringify(data))
    },
  },
})

export default store
